<%@ page isELIgnored="false" %><%--isELIgnored=true禁用EL表达式--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- JSTL标签库是一个JSP标签的集合，封装了许多jsp应用程序通用的核心功能-->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
    <style>
        #d1{
            margin-left: 20px;
            margin-top: 20px;
        }
    </style>
</head>
<body>
<div id="d1">
    <button class="layui-btn" type="button" onclick="refund()">一键退款</button>
    <!-- <table class="layui-table" lay-even lay-skin="nob">
            无边框表格（内部结构参见右侧目录“常规用法”）
        </table> -->
    <table class="layui-table">
        <!-- colgroup中可以使用col来定义表格单元格宽度， -->
        <colgroup>
            <col width="50">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th><input type="checkbox" name="allsel" lay-skin="primary" onclick="checkAll()"></th>
            <th>订单号</th>
            <th>用户ID</th>
            <th>用户名</th>
            <th>交易金额</th>
            <th>交易时间</th>
            <th>订单状态</th>
            <th>退款理由</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="order">
            <tr>
                <td><input type="checkbox" name="orderStatus" lay-skin="primary" value="${order.orderNo}"></td>
                <td>${order.orderNo}</td>
                <td>${order.uId}</td>
                <td>${order.uName}</td>
                <td>${order.orderMoney}</td>
                <td><f:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>
                    <c:if test="${order.orderStatus == 1}">待付款</c:if>
                    <c:if test="${order.orderStatus == 2}">待发货</c:if>
                    <c:if test="${order.orderStatus == 3}">已发货</c:if>
                    <c:if test="${order.orderStatus == 4}">已签收</c:if>
                    <c:if test="${order.orderStatus == 5}">退款中</c:if>
                    <c:if test="${order.orderStatus == 6}">已退款</c:if>
                    <c:if test="${order.orderStatus == 7}">交易结束</c:if>
                </td>
                <td><button type="button" class="layui-btn" onclick="update()">订单详情</button></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div id="test1" style="text-align: center;"></div>
    <div style="text-align: center;">
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(1,${totalPage})">首页</button>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo-1},${totalPage})">上一页</button>
        <span class = "layui-font-16">${pageNo} / ${totalPage}页</span>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo+1},${totalPage})">下一页</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(${totalPage},${totalPage})">尾页</button>
    </div>
</div>
</body>
<script>
    function refund(){
        // var arr = [];	//声明一个数组用来存放遍历出来的checkbox value值
        // $("input[name='productState']:checked").each(function(i) {	//遍历
        //     arr.push("productId=" + $(this).val());	//将我们遍历出来的值push到数组中
        //     //最后可以提交arr就可以实现将我们选中的checkbox的value值提交
        //
        // });
        var userList = new Array();
        $("input[name='orderStatus']:checked").each(function(i){
            var i = $(this).val();
            userList.push(i);
        });
        console.info(userList);
        $.ajax({
            url:"http://localhost:8080/shopping/order/refundGoods",
            data:{ids : userList},
            type:"get",
            dataType:"json",
            success(obj){
                if(obj == "1"){
                    alert("退款成功");
                    window.location.reload();
                }else {
                    alert("退款失败");
                    window.location.reload();
                }
            }
        });
    }
    function queryByPageNO(pageNo,totalPage){
        if(pageNo <= totalPage){
            //查询条件
            // var params = $("form").serialize();
            if(pageNo < 1) pageNo = 1;
            window.location.href = "http://localhost:8080/shopping/order/queryAllRefund?&pageNo="+pageNo;
        }
    }

    function checkAll(){
        var obj = $("input[name='allsel']").prop("checked");
        if (obj === true){
            $("input[name='orderStatus']:not(:checked)").each(function() {
                this.checked = true;
            });
        }
        if (obj === false){
            $("input[name='orderStatus']:checked").each(function() {
                this.checked = false;
            });
        }
    }
</script>
</html>